package com.zzx.boot.utils;

import com.zzx.boot.entity.UserInfo;
import com.zzx.boot.entity.vo.UserInfoVo;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.Data;
import org.springframework.stereotype.Component;

@Data
@Component
public class SecurityContext {

    @Resource
    private  HttpServletRequest request;

    private static String KEY = "user";

    public  HttpSession getSession(){
        return request.getSession();
    }

    public  Long getUserId(){
        return getUserInfo().getUserId();
    }

    public  UserInfoVo getUserInfo(){
        return (UserInfoVo) this.getSession().getAttribute(KEY);
    }

    public  void setUserInfo(UserInfoVo user){
        this.getSession().setAttribute(KEY, user);
    }

}
